//
//  WZUpdateSettingController.m
//  ETong
//
//  Created by wanzhao on 15/11/2.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZUpdateSettingController.h"

#import "WZSettingCell.h"

@interface WZUpdateSettingController ()<UITableViewDataSource, UITableViewDelegate, WZSettingCellDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;


@end

@implementation WZUpdateSettingController

- (void)dealloc
{
    NSLog(@"WZUpdateSettingController dealloc");
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = RGBCOLORWITH16COLOR(0xeeeeee);
    self.navigationItem.title = @"更新设置";
   
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, HARDWARE_SCREEN_HEIGHT - 64) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = ClearColor;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.scrollEnabled = YES;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self.view addSubview:self.tableView];
    
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (!IsIOS7) {
        self.navigationController.navigationBar.tintColor = RGBCOLORWITH16COLOR(0x354d6c);
    } else {
        self.navigationController.navigationBar.barTintColor = RGBCOLORWITH16COLOR(0x354d6c);
    }
    
}

- (void)loadData
{
    
}


- (NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WZSettingCell *cell = [WZSettingCell settingCellWithTableView:tableView];
    cell.settingDelegate = self;
    cell.cellIndexPath = indexPath;
    if (indexPath.section == 0) {
        cell.textLabel.text = @"仅在wifi环境下更新";
        cell.isOn = [USER_DEFAULT boolForKey:ISWIFIUPDATE];
    } else {
        cell.textLabel.text = @"退出时清空缓存";
        cell.isOn = [USER_DEFAULT boolForKey:ISClEARMEMORY];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return OppositeHeightRate(10);
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return OppositeHeightRate(10);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return OppositeHeightRate(60);
}


#pragma mark settingCellDelegate
- (void)settingCellDidChangeValue:(BOOL)value withIndexPath:(NSIndexPath *)indexPath
{
    NSUserDefaults *def =USER_DEFAULT;
    if (indexPath.section == 0) {
        [def setBool:value forKey:ISWIFIUPDATE];
        
    } else if (indexPath.section == 1) {
        [def setBool:value forKey:ISClEARMEMORY];
        
    }
    [def synchronize];
    
    [self.tableView reloadData];
}
@end
